/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable react/jsx-props-no-spreading */
import React from 'react';

type TLazyWrapper<T> = (importer: Promise<{ default: React.FC<T> }>, props: T) => React.ReactElement;

/**
 * wrapper with lazy loading
 * @props importer `import({path})`
 * @props props component props tranfered to child
 * @return `<LazyWrapperWithoutProps />`
 */
const LazyWrapper: TLazyWrapper<any> = (importer, props) => {
    const WrappedCompo = React.lazy(() => importer);

    return (
        <React.Suspense>
            <WrappedCompo {...props} />
        </React.Suspense>
    );
};

export default LazyWrapper;
